cmake_minimum_required (VERSION 3.18)
project (mymath)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)

set(Inner_VERSION 1.2.3.4)

include(GenerateExportHeader)

add_library (mymath mymath.cpp)
generate_export_header(mymath)
set_property(TARGET mymath PROPERTY VERSION ${Inner_VERSION})

install(TARGETS mymath EXPORT mymathTargets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
    INCLUDES DESTINATION include
)

install(
    FILES
        mymath.h
        "${CMAKE_CURRENT_BINARY_DIR}/mymath_export.h"
    DESTINATION
        include
    COMPONENT
        Devel
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
  "${CMAKE_CURRENT_BINARY_DIR}/mymath/mymathConfigVersion.cmake"
  VERSION ${Inner_VERSION}
  COMPATIBILITY AnyNewerVersion
)

export(EXPORT mymathTargets
  FILE "${CMAKE_CURRENT_BINARY_DIR}/mymath/mymathTargets.cmake"
  #NAMESPACE Upstream::
)

configure_file(cmake/mymathConfig.cmake
  "${CMAKE_CURRENT_BINARY_DIR}/mymath/mymathConfig.cmake"
  COPYONLY
)

set(ConfigPackageLocation lib/cmake/mymath)
install(EXPORT mymathTargets
  FILE
    mymathTargets.cmake
  NAMESPACE
    Upstream::
  DESTINATION
    ${ConfigPackageLocation}
)
install(
  FILES
    cmake/mymathConfig.cmake
    "${CMAKE_CURRENT_BINARY_DIR}/mymath/mymathConfigVersion.cmake"
  DESTINATION
    ${ConfigPackageLocation}
  COMPONENT
    Devel
)
